package cn.cvs.servlet;

import cn.cvs.service.FruitService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/FruitDelServlet")
public class FruitDelServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        FruitService fruitService = new FruitService();
        int fruitId=Integer.parseInt(request.getParameter("fruitId"));
        int count = fruitService.del(fruitId);
        if(count>0){
            request.setAttribute("info","删除成功！");
        }else {
            request.setAttribute("info","删除失败！");
        }
        request.getRequestDispatcher("FruitListServlet").forward(request,response);
    }
}
